package handler

import (
	"Gin/api/request"
	"Gin/global/model"
	"Serve/VideoSrv"
	"context"
	"github.com/gin-gonic/gin"
	"net/http"
)

func VideoList(c *gin.Context) {
	var VideoListRequest request.VideoListRequest
	if err := c.ShouldBind(&VideoListRequest); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  err.Error(),
		})
		return
	}
	list, err := model.VideoClient.VideoList(context.Background(), &VideoSrv.VideoListRequest{
		Class: int64(VideoListRequest.Class),
		Page:  int64(VideoListRequest.Page),
		Title: VideoListRequest.Title,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "success",
		"data": list,
	})
}
